package com.cardeira.sendsms.server;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class FileUpload extends HttpServlet {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final Logger log =
	      Logger.getLogger(FileUpload.class.getName());
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		SmsEntry se = new SmsEntry();
		se.setPhoneNumber(req.getParameter("phoneNumber"));
		se.setClinica(req.getParameter("clinica"));
		se.setImported(true);
		se.setAppTime(req.getParameter("hora"));
		se.setDay(req.getParameter("dia"));
		se.setPatient(req.getParameter("patient"));
		se.setGuid(req.getParameter("guid"));
		se.setSenderPhone(req.getParameter("senderPhone"));
		se.setSenderID(req.getParameter("senderID"));
		insertSmsEntry(se);
		super.doGet(req, resp);
	}
	private void insertSmsEntry(SmsEntry se) {
		
		PersistenceManager pm = PMF.get().getPersistenceManager();

        try {
            pm.makePersistent(se);
        } 
        catch(Throwable e)
        {
        	log.log(Level.SEVERE,e.getMessage(),e );
        }
        finally {
            pm.close();
        }
				
	}
	
	
	
	
	


}
